refactored read and write to json, needs finishing