Minor refactoring to ensure correctness.