Major revamp of the Python script