Refactoring (mostly to comply with PEP8)