parse algorithm refactoring