Fix the logic to determine working dir