Improvements to CGI handling