Updated code and non-repeat algorithm