Moved logic out of views