Refactoring and sorting of utility functions