reworked function validation, and added variable declaration