making code more pythonic