LayerImpl refactoring/simplification and more unit tests