rewrite of compile and detect scripts

modularized the scripts, dry them out a little, and turn caching back on