move thread.js so it can be used in other libs