bt.cpp copied from 1.3.1