A flexible instrumental variable approach