Fix JS bug found by Dave