Bug fix of potentially dangerous "head" call.

Code to ensure the call to head is done safely when the stack is
empty.
Merge pull request #123 from lornap/fixDangerousHead

Bug fix of potentially dangerous "head" call.