Created closest match function.