Revert "#690 removed redundant code"

This reverts commit 2bcf6f63cafc638950e0aa1a37354afe7cdd6241.
Revert "#690. Implemented a workaround for the tcp bug."

This reverts commit b39a05272fc0edc40a15cba2f4aeb0527d1950d2.