Extracted match function and changed return values to int from boolean
to prepare for near matching.