Bugfix for last commit (fixed #349 (Gateway can lose connection to portal and doesn't reconnect properly))