Write main funciton