Refactoring of loadData to reduce duplicate code