made code more pythonic