Changed the order of pulling and copying to avoid race condition.