More work on the rewrite, plus bugfix

Fix Brickimedia/brickimedia#92 for the rewrite