if-let was def not working correctly