Refactor parser internal implementation