Various improvements.

Please let me know if you require any changes.

Thanks for the plugin.
I thinks this method and the next one are not being used in this change. Do you really need these?