refactor data handling