make code more pythonic