added bottom up version