added automatic gateway recognization