clean up and modularize pieces of template