Switched from "Events" to "lock" to prevent stack overflow on large querys