fixed several silent bugs in logic.r, tidied partial