Fix for issues in GH-104 branch with failing node unit tests and made code jshint compliant.

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?