Upgated code to reflect final changes