Refactor parser and stack