refactor msg handler(not finished)