Fixing bug in bt.prep and adding some helper functions