Updated message handling to prepare for JSON requests