Refactor to function.
Tests added.
Merge branch 'devel'