updated calculations and added tests