Ongoing refactoring. WIP.