added implementation from Marc