cleaned code with layer plotting