Moved some functions to a common file