refactor parsing algorithms