fix some notices reported by simpletest, plus a logic error