Added a unit test. Fixed the implementation. Maybe still a bit naive
when it comes to intervals that are too small to keep up with?