Make code more pythonic