Refactored check_if_account_exists function