fix dequeue for empty

`dequeue` should return `0` when no queue exist or queue is empty.
Merge branch 'fix-dequeue-for-empty'

Closes #1217