Use more pythonic code