Single-threaded implementation and some tests written