that kind of helped, the code makes a lot more sense now,
but now all the squares except the corners have end_peice set to 0 and don't spawn squares
Also if I move just a little bit in any direction it crashes from running out of entities.