Fixed custom variable optionallity and some bugs in the template