JSON mode made a little better+refactor