Template refactor to remove duplicate code.
Backend refactor to cut down on duplicate code
cleaned up crufty old files
refactor bugfix