Moved logic in javascript to controller