refactored to more pythonic