Improved TCP message handling