rewritten scanner/parser