added a function determine the next given