added println statements and changed few calculations based on the result