Refactored the validation procedures
Moved some code to sql-intern.scm