Big refactoring where general data structures have been moved to
separate package