Fixed a bug with pop, tightened critical sections