Added semaphore in borrow_connection(); Cleaned up