Rewrite robust logistic using plpythonu and clean code