partial refactoring work; not finished