Bug fixes and tweaks

Various small fixes