finally got calculations working, thanks to sam