added tests for messages, code cleanup