Bugfix #1125, #1216.

Code Review: http://mrccodereview.cloudapp.net/ui#review:id=7323