major refactoring, including stuff the existing code into a nx object