Up-to-date with lordvlad`s fork (adapted for current implementation).