Changed code to be more pythonic.