added function to calculate payment