Handle various corner cases a little bit better