major restructuring of code into Model