Management thread reworked, added gateway mode