better error handling while checking for existing record