Improved parsing to fix undesired results