changed solve function to return the path to the solution in the right order instead of reversed