Possible recursive function to stay on path