re-wrote for new plugin API