added input length error checking in adding to bag