Major refactoring for performance and code cleanup.  Fixed issues around hint sorting as well.