optimize the thumb detector function.