Updated validation function to return correct values