Fixed a bug with removing elements