code formatting and moving common code to calculations.js