Issue38

I've implemented the fix Rick suggested - the code had many instances of what turns out to be a web2py antipattern (something to avoid).  I've removed these and the speedup seems to be about 12x.  Whether this will resolve the timeout issue remains to be tested on the production server.  Output has been compared with previous output for several studies (including study 60, which caused the timeout) as well as nexml validated.  This pull also fixes issue41, which required changing the case of one character.