alternative implementation of prepare_data