Fix some bugs, making progress with the templates