Cleaned up Solver code

- Split build_problem out into a separate function.
- Use a Map rather than a Hashtable for the cache. Makes it easy to get
  a simpler read-only version, once building is complete. Also, saves
  having to sort the results.