revise sleep logic

avoid the sleep call if it's not necessary, and do it before the api
call, not after it

Also add some debugging for a milestone error that is showing up in the
import log