split min_spt function into 2 fns