put entities into an array so order of encoding can be guaranteed, fixing issue #369