completely rewritten layout algorithm to be totally correct, now a topological sort of the pieces is calculated for each level by taking into account which piece overlaps any other and building a graph of all of them