Made code more pythonic