Added error checking in deletion functions