completed layered frame example, some refactoring