Added an error calculating funciton