rewrting color code to get autoselect of layers and colors to work
fixed merge conflict