change some code to be more pythonic