This implementation will need to be (almost completely) changed when we implement multiprocess support.