Changed to use plugin structure. Plus a few fixes.