use seq_along(sol) in place of 1:length(sol)