add server side validation, refactoring