fixed a couple of bugs and added better checking for derivative API adherence.