add support for export to json; various other fixes