Mild reorganization of files and source clean up.
Fixed bug where generation will crash when max(items) is a perfect square.