refactor npio code