greatly simplify build files, factor out duplication, fix some issues