first implementation of rest interface + some refactoring