fixed another null/undefined bug and added test cases for both