improve before hook in mvc example