refactoring form selection checking
add error handling