Fix NPE and layer removal bug