reimpl. of bottomup