Refactored tiger bug solution.