Refactor plugins (Remove duplicated code).

Fixes #74 #71