Add script option parsing mechanism

Script option parsing mechanism implemented. Restructure the script so that it suit the new option parsing mechanism.