Pop method does not work if array is empty