layer feature added, plus some more javascript refactoring