Fix crashes.

Fix a Divide by zero crash and NPE on view clear.
I'd rather catch the root cause of the NPE instead of a huge try-catch block here...