Turn curves into a close rectangle

maybe this helps

Also, the direction in which a wall has been drawn makes a big defference