Added null-checking test cases

Also a couple fixes for null checks