Delete function more clever now

Delete function more clever now