Add input validation and tests