Updated for multisets and better error catching