Improve and correct test harness
Clean up lib/*.js and make consistent with other modules