truncate TCP working (needs more testing), functions cleaned up