Sync with evaleev/BTAS: can compile with g++ now

Includes Miles' fixes.