tests: added tests, moved some code into services
merge master