Significant general refactoring - WIP