Renamed variables and implemented 2nd order derivatives