refactoring form checking