Fixed numerous bugs, refactored so that we don't need msg_id anymore.