moved logic out of ui and into controller