Some fixes and improvements from the master branch.