Use List's headOption to increase readability.
Add methods to BaseAlgorithm to avoid many isInstanceOf checks.
Merge pull request #19 from vigdorchik/head_option

Use List's headOption to increase readability.