cleaned up matching code