Create LayerModel, put all layer related code in it. Refactoring.