Fix bugs in extension building/extracting code (reported by JoeDF)