main gateway scipt