improved parse logic