Move some functions to a better place