Memory leak fixed + PEP-8 overhaul + some refactoring