Refactored to work as a plugin