Replaced tabs with 4 spaces and other PEP8 fixes.
Making fix closer to Lachlan's suggestion.