Added the complete code for closest match module