Fixed bug in readLine loop and added a counter