Speed improvments. Fix for layer selection.