bug fixed, max stack implemented