Whitespace cleanup and python3 compatibility changes

The same as earlier but with two similar commits squashed to single one.