gs algorithm
cleanup