fix minor issues and reorganize parser a bit