alg seems to working top-down