minor bug fixes, see TODO for details