Fixed a bug with calculations