Bug fixes

Fixes bug in runtime
Workaround for bug #92
Various other minor code fixups.