fix typo and JSON.stringify write
added test