Remove dependence on setImmediate