More refactor, and fixes.