Updated filter function

layers get removed before new ones are added