Refactor parsing logic into method. Noted it might be made more generic later on.