Mostly working. Fails on the end edge case I think. I need to make some better tests