Cleaned up code, and now sort results by score properly.