Moved around apply_msg method to make it more generic