Code upgrade. Have been working on this in a separate project