Use local storage for poll directive

Fix #197.

Also misc bug fixes/refactoring of poll directive.