Move some code from views to helpers.