change bit-wise AND to logical AND, and other minor fix