giant refactoring that works in single-user mode but not in multi-user