improve logic in parse