fixing bugs and making templates work correctly