Implemented using threads and locks. Coding style fixes.