refactorization of parsing code