private List<Layer> makeLayersHierarchy(List<Layer> layers) {
        LinkedList<LinkedList<Layer>> layersStack = new LinkedList<LinkedList<Layer>>();
        ArrayList<Layer> rootLayers = new ArrayList<Layer>();
        
        for (Layer layer : layers) {
            switch (layer.getType()) {
            case HIDDEN: {
                layersStack.addFirst(new LinkedList<Layer>());
                break;
            }
            case FOLDER: {
                assert (layersStack.isEmpty() != true);
                
                /* meer dan 5 layers diep? nullpointer hiero */
                if(!layersStack.isEmpty())
                {

                    LinkedList<Layer> folderLayers = layersStack.removeFirst();
                    for (Layer l : folderLayers) {
                        layer.addLayer(l);
                    }                	
                }
            }
                // break isn't needed
            case NORMAL: {
                if (layersStack.isEmpty()) {
                    rootLayers.add(layer);
                } else {
                    layersStack.getFirst().add(layer);
                }
                break;
            }
            default:
                assert false;
            }
        }
        return rootLayers;
    }