added previous logging and popping functionality with tests