Refactored for more pythoniness