Clean up unused code and restructure templates