Updated main fuction