Factored out common view logic.