Cleaned code for wrap it into a plugin.