sort vars alpha and fix a few issues on the way