Investigating bug in if condition