Updated the code to return data after pop.