Fix for issues in GH-104 branch so nodeunit tests now complete succesfully

I fixed the issues in GH-104 branch by making sure no events are being emitted after gaze was closed. Also fixed some tests by adding some timeouts to prevent additional bleeding.

Refactored code slightly to be jshint compliant.

Also changed the safewriting test so it passes. Can you confirm that this is not breaking the test and it still tests what it should test?