19
Very nice work indeed!
Some remarks, but I guess this has to do with the original code:
It seems to tend to add content from the right: if you have on the first row, one module with less blocks, one with more blocks and then two with less blocks, then module 5 and 6 are placed on the second row below 3 and 4 and the space at the left below module 1 stays unused.
In my case module 5 is also longer than module 6 and module 7 8 9 are below 6. Modules 10 and 11 start again at the left below (with many whitespace) 1 and 2.
Would it not be possible to determine how long each module gets and sorting them before displaying, so the ccolumns are more equally filled?