Fixed the bitflag conditions. They were totally wrong (off by 1). Oops!