Fix exception in some (literally) edge cases.