if statement working correctly