Refactoring and api update