added multiple threads support