Added logic to determine the top-level directory.

  Relates to issue #3.