Some refactoring to be more PEP8 and some barbarian optimization