Fixing some condition logic