Implement handlings of corner cases of and add the tests