Added edge case checking to match specs.