Make the code actually work by moving most of __init__ into templates
Apply various python idioms