Optimise connect function, only connects if the new connetion will be different to the previous one
Fixed a few warnings