Refactor layers panel func