Add plugin manager tests and fix some bugs