refactor parsing code, remove unused code