Continue refactoring and start bugfixing.

Due to previous refactorings plugin was completely broken. Now this
problem is almost fixed. Everything seems to be working expect graph
image generation, but it's expected at this moment.