almost finish local mode, not working yet