Grabbed new calc code from forum