This feels like the wrong place for this function, since it's dealing with multiple threads. Maybe helpers.rb?