Refactored another function and included it into the unit tests