refactor script_task.rs fn handle_msgs