Fix realtime and further refactor.