Imporve algorithm performance

TODO: the mutual information calculation seems to be problematic.