Better template management and some fixes