Template refactoring, style changes, removed debug mode