Improving logic for boolean validation