Massive refactoring. I don't know if it even works. I'll worry about that tomorrow.