Various correctness fixes.