Fixes #46 and refactors json generation for preview