Moved some global functions to a helper file