part way through major refactor