added a setTimeout to force callback to end of event loop