move part of code to service