add tests and separate main from service