Function pop() work not correct