improved parsing logic, slightly