Refactored line parsing