Refactored: extracted readLine method and renamed vars.