factoring of prepare_data