Working version without using PCD thread