Adding code to limit retrieving data updates when similar to the last query. Adding safeApply helper function to avoid duplicate apply calls.