Some fixes, and a feature

See commit log for details.