this function and the next have some common functionality