Reworking of the original one. Written in Java.