Updated Working Code