Jython and recursive fix

This includes two fixes. 

It fixes Issue #370 and #286.

The Jython fix should be solid. The recursion fix on the other-hand could be solved on a deeper level. As I don't know the exact behavior behind this change, but based on my testing it has only had a positive effect.

If the recursive fix is not to your liking I can make a separate pull request with only the Jython fix.