Refactor code not to parse twice