Refactor credentials lookup