Refactor credential setting