Algorithm for processing data from file