refactor to simplify parse code