Few changes to mod derivative

Sorry for the delay, here are the changes I planned to make to your PR.
If you are OK with them, you can simply accept this PR, then we will merge yours.