Sam api refactoring