Improve getspent_r/endspent