Restructure document node implementation * Implement topological sort * Enforce the usage of type annotations * Add complete test case