Refactor for service

It is in a new stable version. Ready to be used in another project as a gem.