Changed sort order, more Python code