fixing validate function