large scale refactor