Split tests in multiple functions.
Add comments and better logic.
Close streams at the end of every rendering instead that closing them all at
the end of the full rendering.