heavy refactoring - DO NOT MERGE INTO OTHER BRANCHES (yet)