bugfix and test code for the theta derivatives