Made code a bit more pythonic