fix number of boundaries check