Deal with undefined layers properly