added validation and flash messages