Added explanation of algorithm in case I take a long break.