moved CGI and IO into separate files