threads05: refactor common functionality