make the function more general