moving helper function to a better place