initial single-threaded solution