Optimizing memory usage in routes and stops detection