Move common code to ApplicationController