improved speed

improved algorithm for searching within the learn matrix.