Various bug fixes and improvements.
Merge remote-tracking branch 'origin/master'