fixed database update logic, added delete query