Cleanup and compatibility with Python2.6