mainlayer refactor