major refactor in preparation for other changes