Moved controller stuff into a class.