Fixes bug caused by incorrect use of assert.
Adds support for build on demand flags.