Wrote reading algorithm.