restructure the check logic