Fix various bugs in calculations, added figure, and improved functionality.