Crazy algorithm!