Performance/bug fixes in the update_statistics task