re-work to be more like mvc pattern