refactor tests

Fix some minor un-reported issues and make sure that window.console is restored properly.