fix incorrect layer selection

was picking the wrong layer when layers were turned off
now it works as expected