Rewrote calc() so it isn't a total mess.