Fixed potential null reference exceptions.
More code reduction surgery.