Added flags/arguments. Refactored TCP part to own function