US stocks end week with gains