nls refactored