gold ends higher, shakes off early weakness