fixed bugs and now produes a valid json string