PR fixup move removeLayer outside if block