Some refactorings, increased speed a lo by reading by line instead of by byte