Implement LimitStack to prevent undo overflow

Signed-off-by: Harsh Gupta <gupta.harsh96@gmail.com>
Should make this private: `var stack = []` after line 4.