final code without table templates