Refactoring in getting data