Complex function divided in smaller subfunctions

+ new data_preparation() function