add client-side and server-side validation; refactoring