significantly improved engine.py for nodes. Needs testing before functional