single-threaded implementation