Problem in Game Logic

Hello all,

i started coding a new Game Idea, yesterday. I think i have a logic problem. The Rectangles that gets generated sometimes don’t border on each other. 

https://www.dropbox.com/s/k33lr2ehw2b0mez/Ohne%20Titel%201.tiff

And Sometimes there is a wide gap between the generated rectangles.

Link to main.lua : https://www.dropbox.com/s/1pjoomlmyagbo89/main.lua