Added final round of tests.

Huge refactoring reducing a lot of code lines, mostly, fagocited "$socket" service.