Fix Code Issues, Refactored Calculation of Records