Fixing context setup and closing