Bug fixes and cosmetic improvements