Refactored api and assert code