Fix a bunch of corner cases