Final working code of dirty sharing