Significant change to inner workings

Now, the algorithm is more robust against noise. The downside is that it
is more difficult to use in conjunction with interrupts.