nio2 slightly refactored (to be debugged)