fixed bug in line counting and added comments