Use a binary instead of a linear search in findChild and containsPositionImmediate
Address more suggestions and bugs from @rlim's code review.