Remove code duplication in create_app.

small refactoring.