Fixes array index issue in tagging JavaScript