fix bug
merged code from cnnic/niot