Refactored plugin to work with rewrite branch.