Overhaul of prepare_data