created update_data function and wrapped plot into another function