This is a _mostly_ working port of my original C++ code. Some parts aren't too optimized yet and some stuff may actually not work. But it's _mostly_ there. :)