Refactorised code and included test skeleton file.