Got it working! Time to work on thread safety. I also need to write up some proper tests.