Added contact sorting and improved contact filtering. Oh, and some minor cleanups.