calculator functionality (almost complete)