Ok, it's done.
I've removed some top level functions, delLog, appendLog, and writeLog.
Q.allSettled, because the code is dealing with callbacks, so the promises will be undefined with Q.all(), Q.allSettled waits until every promises is fulfilled or rejected, Q.all just collects or promises.