added updated implementation