Add docstring
Add docstring; change open from default mode to U
Add docstring
Change HTML string generation method; change test

Instead of building up the string by successive string concatenations,
instead build up a list and then use string.join to build the final string
Add comments explaining how study_id is retrieved

Code was slightly unclear, comment should help!