refactored. Generalize parser