Move some generic functions to `utils`