added api service plus some refactoring