fix asynchronous issue with storage module

Issue #885
note that the `clear` function should also be modified in the same manner, but because it's not used currently in unloading events handlers, and there is some issue changing it because it calls the asynchronous `keys` method (which i didn't want to make it synchronous), I've pushed this commit first to resolve the current bug.

the second commit is just for formatting, I've split them into two separates commits so modified code can be displayed more clearly.

in the third commit, I've added the matchElement function suggested by ianb in #889