Complete overhaul to be compatible with callback.