updated to properly check delete flag