Refactor init and fix init white screen error

Init has been cut into several functions
init_tpl is called again after creating tmp/ dir in install