finished refactor of nan family of functions with passing tests