Modified script, replaced more codes with latex