Work in progress: heavy refactoring