Added errors codes and refactored TCP generator