More refactoring, but not compiled on linux yet.