did numerous bug fixes and cleanups; now more efficient and prints in increasing order