Updated validation function