Added a function to shutdown ms after exiting
Adjusted design a bit