Bug fixes in insert/remove