A more efficient read

since I learned that the previous algorithm is in fact quite slow