added validator and refactored some validation functions