added a if exists clause, needs testing