Move calculator code into functions