Remove duplicate code in views.