moved code to tempaltes