refactor
move application logic to nm.c