made code more pythonic/functional