Bug fixes

Various minor fixes