BUGFIX: make sure to check the length of matching array