refactored base path logic