refactoring, started from the bottom with parser