Addresses various problems pointed out by Nikerabbit in https://gerrit.wikimedia.org/r/#/c/43850/

Change-Id: Ib6ad4531f5e2372e183931690fea044dd52a4d8f