Working version with configurable threads