fixed some bugs in derivatives