Added code to detect duplicate