refactored json generation