Move some code into refreshApplication.