Move msg functionality into separate file