Add further precondition checks

This makes pop() and peek() consistent with first().
Merge pull request #545 from guoguo12/patch-1

Add further precondition checks