Wrote more efficient CPU algorithm