some improvements

Well, I was bored and wanted to take a quick look at your code. This is the result.
I haven't touched any code relevant to hashing, so the plugin should work just like before. I only improved the overall code.