Added some debug statments and fiddle with Layer.save