Using lock to have 1 connection at a time