WIP refactoring but need to squash prev commits into gerrit