Simplifying logic, and removing the 10ms timeout, replacing it with setImmediate.  This will be faster, but still allow other functions to fire in the event loop