added plugins and improved middleware api