first part of major refactor