Added additional error checking for some edge cases, and test cases to validate them