added some checks, and reset B when triggerd
adjusted the check first