initial refactoring into parser, with simple tests