Optimized template
Added data validation