diff --git a/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisAdaptor.pm b/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisAdaptor.pm
index 341748ffb94cd193ee120c1c850333849df05f28..77d78a410f0f026fa248d49dd63c595b44b4ae8e 100644
--- a/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisAdaptor.pm
+++ b/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisAdaptor.pm
@@ -116,7 +116,11 @@ sub fetch_all_by_pattern {
 
     my $analyses;
 
-    if( $pattern=~/^\d+$/ ) {
+    if( not defined($pattern) ) {
+
+        $analyses = $self->fetch_all();
+
+    } elsif( $pattern=~/^\d+$/ ) {
 
         $analyses = $self->fetch_all_by_analysis_id( $pattern );
 
diff --git a/modules/Bio/EnsEMBL/Hive/Queen.pm b/modules/Bio/EnsEMBL/Hive/Queen.pm
index 8ce192235cce6586b261ccc6357b13d9e5db4f69..b7184918c9af04c70035415f2481cb1b600fa064 100644
--- a/modules/Bio/EnsEMBL/Hive/Queen.pm
+++ b/modules/Bio/EnsEMBL/Hive/Queen.pm
@@ -272,7 +272,7 @@ sub specialize_new_worker {
             }
         }
             # probably scheduled by beekeeper.pl:
-    } elsif( $stats = Bio::EnsEMBL::Hive::Scheduler::suggest_analysis_to_specialize_a_worker($analyses_pattern, $worker) ) {
+    } elsif( $stats = Bio::EnsEMBL::Hive::Scheduler::suggest_analysis_to_specialize_a_worker($worker, $analyses_pattern) ) {
 
         $analysis = $stats->analysis;
     } else {
diff --git a/modules/Bio/EnsEMBL/Hive/Scheduler.pm b/modules/Bio/EnsEMBL/Hive/Scheduler.pm
index 1d0955f35e7ed189b201f8f062a1a71910743489..5ab07e450c112b3ed52511ea843008b35b152264 100644
--- a/modules/Bio/EnsEMBL/Hive/Scheduler.pm
+++ b/modules/Bio/EnsEMBL/Hive/Scheduler.pm
@@ -124,24 +124,17 @@ sub schedule_workers_resync_if_necessary {
 
 
 sub suggest_analysis_to_specialize_a_worker {
-    my ( $analyses_pattern, $worker ) = @_;
+    my ( $worker, $analyses_pattern ) = @_;
 
     my $queen               = $worker->adaptor;
-    my $analysis_adaptor    = $queen->db->get_AnalysisAdaptor;
     my $worker_rc_id        = $worker->resource_class_id;
     my $worker_meadow_type  = $worker->meadow_type;
-    my @only_analyses       = ();
 
-    foreach my $analysis ( @{ $analyses_pattern ? $analysis_adaptor->fetch_all_by_pattern( $analyses_pattern ) : $analysis_adaptor->fetch_all() } ) {
-
-        next if($worker_rc_id       and $worker_rc_id!=$analysis->resource_class_id);
-
-        next if($worker_meadow_type and $analysis->meadow_type and $worker_meadow_type ne $analysis->meadow_type);
-
-            # if any other attributes of the worker are specifically constrained in the analysis (such as meadow_name), the corresponding checks should be added here.
-
-        push @only_analyses, $analysis;
-    }
+    my @only_analyses       = grep { !$worker_rc_id or $worker_rc_id==$_->resource_class_id}
+                                grep { !$worker_meadow_type or !$_->meadow_type or ($worker_meadow_type eq $_->meadow_type) }
+                                    # if any other attributes of the worker are specifically constrained in the analysis (such as meadow_name),
+                                    # the corresponding checks should be added here
+                                        @{ $queen->db->get_AnalysisAdaptor->fetch_all_by_pattern( $analyses_pattern ) };
 
     return schedule_workers( $queen, 1, $worker_meadow_type, \@only_analyses );
 }