fix ns bugs and add a test