Some refactoring for PEP8, better naming and future testability