Worked on several things to fix. TODO: Improve the parseTemplate function - does not work sometimes