Added shift/pop and fixed json encoding