More robust tree parser