fixed bug in boundsCheck