Fix bug when reading lines; also correct cast to int