Refactor of context manager and nodes

This is a more simple implementation and fixes #242 as a result.