Refactor validation (still not working) into helper function