made some progress on the match function