addlayer refactor