Fixes a mistake a made. After lots of testing I feel that this is stable enough and works reliably.