fix logic bug in conditional statements