refactoring some of the main bits...