Tricky to do in the face of callbacks, but I can try reworking it to use the async module (https://github.com/caolan/async) and it would probably come out cleaner.