fixed some bugs in calc logic