refactor data loader and common functions