Updated Code with all functionalities