Clear up the code and add MessageManager.