More refactoring. Maybe it actually works.