move data output code to the view