Cleaning up the common python code
Refactoring still
Adding generator tricks