fix empty message issue
added test
some cleanup