Split main.json

Fixes #2582, #2572, and has some minor fixes for splitting main.json file.