How to simplify this condition