Rewrite the following script to make it cleaner and more reusable. Some part of this script could be used in future other script.

<script>
"""
Live area detection from TI data.
Run this script with the following parameters: --conf=conf/live_area_detection.json
"""
import math

import numpy as np

from radar_toolbox.fmcw_utils import RadarModel
from radar_toolbox.utils import configure_argument_parser_for_conf_file, load_conf, get_reader_from_config, \
    points_inclination_correction
from radar_area_detection.detection import AreaDetector
from radar_area_detection.comm.camera_alert import CameraAlert
from radar_tracking.tracking_utils import get_capture_limits_from_conf, get_clustering_algo_from_conf, \
    get_cluster_tracker_from_conf

if __name__ == "__main__":
    args = configure_argument_parser_for_conf_file()
    config = load_conf(args.conf)
    rabbitmq_conf = load_conf(config["rabbitmq_conf"])
    if rabbitmq_conf["enable"]:
        from radar_area_detection.comm.rabbitmq import RabbitMQSender
        import json

        rabbitmq_sender = RabbitMQSender(host=rabbitmq_conf["host"], port=rabbitmq_conf["port"],
                                         queue=rabbitmq_conf["queue"], exchange=rabbitmq_conf["exchange"])
        rabbitmq_sender.connect()

    cfg_file_path = config["cfg_file_path"]
    radar_model = RadarModel.get_model_from_str(config["model"])
    min_velocity_detection = config["min_point_vel"]
    horizontal_inclination = vertical_inclination = None
    if config["horizontal_inclination"] is not None:
        horizontal_inclination = math.radians(config["horizontal_inclination"])
    if config["vertical_inclination"] is not None:
        vertical_inclination = math.radians(config["vertical_inclination"])

    tracking_conf = load_conf(config["tracking_conf"])
    frame_grouping_size = tracking_conf["frame_grouping_size"]  # How many frames do we want per step
    dt = tracking_conf["frame_interval"] * frame_grouping_size  # Delta time between two steps
    verbose = tracking_conf["verbose"]
    capture_limits = get_capture_limits_from_conf(config=tracking_conf)

    clustering_algo = get_clustering_algo_from_conf(config=tracking_conf)
    cluster_tracker = get_cluster_tracker_from_conf(config=tracking_conf)
    local_display = config["local_display"]
    if local_display:
        from matplotlib import pyplot as plt
        from radar_area_detection.display import AreasDisplay2D
        from radar_visuals.display import PlayingMode

        areaDisplay = AreasDisplay2D(dt=dt, capture_limits=capture_limits, playing_mode=PlayingMode.NO_WAIT,
                                     time_fade_out=tracking_conf["time_fade_out"])

    area_conf = load_conf(config["area_detection_conf"])
    alerts = None
    if area_conf["camera"]["enable"]:
        camera_alert = CameraAlert(ip=area_conf["camera"]["ip"], port=area_conf["camera"]["port"])
        alerts = [camera_alert]
    area_detector = AreaDetector(areas=area_conf["areas"], alerts=alerts)

    # Configure the serial port
    reader = get_reader_from_config(config=config)
    reader.connect(cli_port=config["CLI_port"], data_port=config["data_port"])
    reader.send_config(cfg_file_path=cfg_file_path)
    reader.start_sensor(listen_to_data=True)

    try:
        while True:
            result = reader.parse_stream(only_points=True)
            # check if the data is okay
            if result["data_ok"]:
                if result["detected_points"] is None:
                    points = []
                else:
                    points = result["detected_points"]
                    if radar_model == RadarModel.IWR6843AOP and min_velocity_detection is not None:
                        points = points[np.abs(points[:, 3]) > min_velocity_detection]
                    points = points_inclination_correction(points[:, :3], horizontal_inclination, vertical_inclination)

                    points = points[np.all(capture_limits[:, 0] < points, axis=1)]
                    points = points[np.all(points < capture_limits[:, 1], axis=1)]

                # Tracking
                clusters, noise = clustering_algo.clusterize(points)
                cluster_tracker.TrackNextTimeStep(current_clusters=clusters, verbose=verbose)
                # Intrusion detection
                area_detector.update(clusters_up_to_date=cluster_tracker.tracked_clusters)
                if local_display:
                    areaDisplay.show(clusters=cluster_tracker.tracked_clusters, area_detector=area_detector)
                if rabbitmq_conf["enable"]:
                    json_data = {
                        "areas": area_detector.serialize(),
                        "clusters": cluster_tracker.serialize()
                    }
                    json_data = json.dumps(json_data)
                    rabbitmq_sender.send_json(json_data)
    except KeyboardInterrupt:  # Stop the program and close everything if Ctrl + c is pressed
        pass
    finally:
        reader.disconnect()
        if local_display:
            plt.close('all')
        if rabbitmq_conf["enable"]:
            rabbitmq_sender.disconnect()
</script>