Add input checking.  Refactor for style.