Add ordering by sources count and fix some bugs.