Added support for orientation, automatic call to recognize() when needed, iterator invalidation check. Thanks to Iain Reid for suggestions.