fixed a terrible bug and optimized some calculator