Fixing some python code to make it more pythonic