better printing, fixed bugs in JSON construction