moved function definitions and derivatives to one file