somewhat painful refactoring, moved around some packages, more work here needed