Clean up handle-message, fix some bugs