Moved history to separate file. Updated algorithm.