Moved Functions to Services

you could probably pull in the code from lib instead of repeating it here.