fix input/output ordering issue