Refactoring for clarity. Added a test to express some hidden behavior, like exception throwing.