Refatoring some methods into MsgFactory class of api package