Bugs found by fred, small cleanup, typos, mismatch in id