Works with a single thread