Nice algorithm!