reorganized ctx initialization