moving validation to another function for better code reuse