stack with max. should probably switch to using java.util ll