refactoring the nandd thread code