Improve code style to be more readable.

- Replace seperate except clauses which have the same result with a list
  of exceptions to catch.
- Replace an 'if not x is None' with 'if x is not None'.
- Change some whitespace.