create check_max_boundary and inline boundary checks