Working Version after merging Igor code with mine.