With a minor glitch in the previous program this is the final version