refactored out some duplicate controller code