Fixed import error and improved handling of existing links