refactor code for formula parser