made validation a function rather than its own script