Fixed wrong index variable being used when looking for valid modes
Fixed size sorder

The comparison function needs to return int, not boolean