Fix issue with inserts not working correctly due to incorrect calculations.