Minor cleanups and correctness improvements.