refactored to have separate connection and message classes