Finalised the connection fucntion