refactoring and add new api endpoints
fix unittests