Refactored the double if