Fixed a bug that caused layers to turn off in the wrong order.