Various fixes.

Details in commit log.