Incremental improvements and bug fixes

Changes are already grouped by commits.