add writeJsontoFile
Fix several little bugs, now it seems working well