refactored and simplified message format and parsing logic