sorting, saving, and likelihood computation