Conditional Logic not working as expected