My latest attempt on fixing some details - however, it's not working (the replace functionality of jinja does not seem to work for unkown reasons). I could swear it was working initially.