Layer marking refactoring
Bugfixes