Final working code - Before Demo