added tests for message handling, fixed found bugs