Code cleanup, renames, and general bug fixes.