Fix an issue with ip-less gateways and some code cleanup