created a almost fully functional match function