Cleaned up plugin - removed lots of redundant code