Properly remove while iterating (fixes crash)