Refactored parseLine function