Fix several issues reported in ticket #4245.