refactors layer functions into one