Moved logic into controller