add logging to enable the tracking of internal data; refactoryed