More refactors, fixed compile errors.