Fixed bugs found in review of commit 46ee9e4476e48a7f7b453dd6f8629032de9c6733