fix foreach bugs, add sort function and test for ReviewCollection, refactoring