adding code to close files
adding caching script
adding json cache of tables
abstracting merging to helper method