finish main funtion