fixed a bug in _extract_layers method.