Refactored by making a constructor, and factored out some path logic duplication.