Refactoring and improving getAll logic