Translated most stuff, introduced some bugs.

Also, this algorithm while making sense is also not very fast I think.
Added check for unreachable code which is not in -Wall for building all targets.