fixed bug with parenthesized atoms
refactor `factor` production code to be less branchy