changed message handling to use emit/publish, and fixed destroy bug