simplify code, remove one obvious bug