add some utils for sorting and comparison
fix #1; fix #4; fix #6