Instead of doing a second for loop, I would just put this code directly in the if(insideBox(...)) loop.