Implemented square spawning algorithm