refactored to use main template