Refactoring query and findObjectId methods