Minor bug fixes, improved algorithm, improved performance