Rubify code

When I started using this project, I was a bit disappointed by the speed. Looking at the algorithms, this isn't really surprising, at some points, the complexity (as in big-O) is larger than it needs be. I'd like to fix this, but to get there, I wanted to first understand the code well enough to make that large of a change. To get there, I tried to simplify the code, which makes use of a lot of non-rubyish ways of doing stuff (mainly because it's a port I guess), but also does a lot of loops, with breaks. I tried to make code like this a bit clearer, simpler and more concise.

I did a lot of stuff in this PR, but most if it is independent of eachother. If you like it, you can merge it, if you say you would want some, but not all, I could make different PRs.

There is one small functional change which I would consider a bugfix. It's clear from the test added what this is. For the rest, the functionality should be exactly the same.