Simplified the logic by combining a condition