Fixed bug in calculations. Added math appendix.