Refactor: more pythonic code