Optimization needed, but the plugin is functional. See comments.