minor refactoring, tested under Python 2.7.5 and Jython 2.7b3