Appendix A: Code Listing

The code can be found here