Adding more robustness to validate function