Main Function updated