DRY-ify template and remove unused code