Splicing from an array while iterating through it seems like a bad idea. Refactoring to build up a result query instead