Refactor plugins (Remove duplicated code).

Fixes #74