add validation, refactor code.