Some fixes and optimizations in the python code (PEP 8 and inter alia)