changed the order of execution of template so directory should exist