moved unique check to top level