Merge from Master, some tweaks and fixes

See commit log. Please consider merging #2241 first, so I can include it in here.