Sorry if the code is a little messy, the idea I was going with is: 1) If an element (point A) == 1, increment rectangleCount and - 2) Change the value to 0 (so it doesn't get recounted at a later point) 3) Check if/how many consecutive elements in the same row are also 1 4) Change all those values to 0 so they don't get recounted 5) Set the variable columnNumber to the value of the last consecutive "1" in that row 6) Check the next rows to see if they have 1s between pointA and columnNumber 7) If yes, change them all to 0