responding to comments

added more comments to the code and tried to ensure floating point calculations are typecast correctly