added working differential function