Refactoring some code in Layer to increase code reuse. Added doc to .gitignore.