Again, break out the body of this `done` handler into a few separate functions that perform discrete tasks, and then invoke them, rather than having 50+ lines of code in one function.