Added line counting and dynamic array sizing