Split up things a bit; more refactoring, speed improvements.