Refactoring Thread.js and its usage example