Refactoring some subs into GeneralTools