First working version. Median time: ~100us