fixed calculations and adding documentation