Small refactor on algorithms.

Signed-off-by: Roland Juhasz <juhroli@gmail.com>