Few changes: made it a little more pythonic