using locks for connection