Several minor bug fixes

- bug 5222
- bug 5242
- bug 5276
- bug 5324