Refactoring + more robust data collection to fix the issue where 'pk' occasionally not available