remove partial JSON's and reorganize optimize_compile to work on multiple files